<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							
							<li>
								用户编号：<input type="text" name="merchantNo"/>
							</li>
							<li>
								用户名称：<input type="text" name="merchantCnName"/>
							</li>
							
							<li>
								用户手机号：<input type="text" name="merchantPhone"/>
							</li>
							
							<li>
								申请状态：<select name="isValid" th:with="type=${@dict.getType('trade_type')}">
									<option value="">所有</option>
									<option value="10A">申请中</option>
									<option value="10B">审核通过</option>
									<option value="10C">审核拒绝</option>
									
								</select>
							</li>
							<!-- <li class="select-time">
								<label>完成时间： </label>
								<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
								<span>-</span>
								<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
							</li> -->
							<li>
								<a id="btnSearch" class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
	 <div id="dialog" class="modal fade text-center">
		  <div class="modal-dialog" style="display: inline-block; width:500px;">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		        <h4 class="modal-title">审核失败原因</h4>
		      </div>
		      <div class="modal-body">
		       	<textarea id="remark"	rows="6" style="min-width: 90%"placeholder="请输入拒绝原因">
		       	</textarea>
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
		        <button onclick="doCheckFail()" type="button" class="btn btn-primary">提交</button>
		      </div>
		    </div>
		  </div>
	</div>
	
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
       var editFlag = [[${@permission.hasPermi('system:hatchetMerchant:edit')}]];
       /*var removeFlag = [[${@permission.hasPermi('system:hatchetMerchant:remove')}]]; */
          var level = [[${@dict.getType('merchant_level')}]];
       var prefix = ctx + "system/hatchetMerchant";
		var tableUrl = prefix + "/selectJLR";
        $(function() {
            var options = {
                url: tableUrl,
             /*    createUrl: prefix + "/add",
                removeUrl: prefix + "/remove", */
                updateUrl: prefix + "/editJLR/{id}",
				exportUrl: prefix + "/export",
                modalName: "客户列",
				search: false,
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
		        {
					field : 'id', 
					title : '客户id',
					visible: false
					
				},
		        {
					field : 'iD', 
					title : '订单ID',
					visible: false
				},
				{
					field : 'merchantNo', 
					title : '客户编号',
					sortable: true
				},
				{
					field : 'merchantCnName', 
					title : '客户名称',
					sortable: true
				},
				{
					field : 'agentName', 
					title : '代理名称',
					sortable: false
				},
				
				{
					field : 'parentName', 
					title : '推荐人',
					sortable: false
				},
				{
					field : 'parentPhone', 
					title : '推荐人手机号码',
					sortable: true
				},
				
				{
					field : 'phone', 
					title : '手机号',
					sortable: true
				},
				{
					field : 'level', 
					title : '客户等级',
					align : 'left',
					formatter: function(value, row, index) {
	            		return $.table.selectDictLabel(level, value);
	            	}
				},
				{
					field : 'liveness', 
					title : '活跃度',
					sortable: true
				},
				{
					field : 'bankAccount', 
					title : '银行卡号',
					sortable: true
				},
				{
					field : 'bankName', 
					title : '银行名称',
					sortable: false
				},
				{
					field : 'submitExamineTime', 
					title : '升级黄金会员时间',
					sortable: true
				},
				{
					field : 'submitReexamineTime', 
					title : '升级经纪人时间',
					sortable: true
				},
				
				{
					field : 'idCardNumber', 
					title : '身份证',
					sortable: true
				},
				
				{
					field : 'upgradeCodeNum', 
					title : '升级码数量',
					sortable: true
				},
				{
					field : 'createTime', 
					title : '创建时间',
					sortable: true
				},
				
				{
					field : 'isValid', 
					title : '升级状态',
					align : 'center',
					formatter: function(value, row, index) {
	            		if(value=="10A"){
	            			return "<b>申请中</b>"
	            		} else if (value=="10B"){
	            			return "<b>申请成功</b>"
	            		}  else if (value=="10C"){
	            			return "<b>申请拒绝</b>"
	            		}
	            	}
				},
				{
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	if (row.isValid == "10A"){
		            		actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="checkSuccess(\'' + row.id +'\')">审核通过</a> ');
		            		actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="#" onclick="checkFail(\'' + row.id + '\')">审核失败</a> ');
		            	} 
						return actions.join('');
		            }
		        }
				
				/*,
				{
					field : 'acqResponseCode', 
					title : '终端返回码',
					sortable: false
				},
				{
					field : 'cardNo', 
					title : '银行卡号',
					sortable: true
				},
				{
					field : 'issBankId', 
					title : '银行简称',
					sortable: false
				} ,
				{
					field : 'acqNo', 
					title : '通道编号',
					sortable: false
				},
				{
					field : 'acqName', 
					title : '通道名称',
					sortable: false
				} */]
            };
            $.table.init(options);
        });
        //审核通过
        function checkSuccess(id){
        	$.ajax({
				url : prefix + "/checkSuccess",
				type : "POST",
				data: {
					"iD":id
				},
				success : function(re) {
					if (re.status == "SUCCESS") {
						$.modal.msgSuccess(re.msg);
						$("#btnSearch").click();
					} else {
						$.modal.msgError(re.msg);
					}
				}
			});
        	
        }
        var orderId;
        //审核拒绝弹出模态框
		function checkFail(id){
			orderId = id;
			//弹出模态框准备输入验证码
			$('#dialog').modal('show');
        	
        }
        function doCheckFail(){
        	var remark = $.trim($("#remark").val());
        	if(remark.length==0){
        		$.modal.alertError("请输入拒绝申请的原因");
        		return;
        	} else if(remark.length>13){
        		$.modal.alertError("拒绝申请原因的字数不得超过13个");
        		return;
        	}
        	$.ajax({
				url : prefix + "/checkFail",
				type : "POST",
				data: {
					"iD":orderId,
					"ykRate":remark  //借用ykRate字段传拒绝原因
				},
				success : function(re) {
					if (re.status == "SUCCESS") {
						//关闭模态框
						$('#dialog').modal('hide');
						$.modal.msgSuccess(re.msg);
						$("#btnSearch").click();
					} else {
						$.modal.msgError(re.msg);
					}
				}
			});
        }
        
    </script>
</body>
</html>